<?php
	class CategoryModel extends Model{
		public $_validate =	array(
				array('category_name','2,20','等级名称必须在2-20位之间',Model::MUST_VALIDATE,'length',Model:: MODEL_BOTH),
				array('category_info','0,200','等级描述不得大于200位',Model::MUST_VALIDATE,'length',Model:: MODEL_BOTH),
		);
		
		public $_auto =	array(
				array('path','getPath',self::MODEL_INSERT,'callback'),
		);
		
		public function getPath(){
			//获取新增分类的路径。即父分类的path连接上父分类的id
// 			echo "aaaaaaaaaaaaaa";
// 			exit();
// 			if(0 == $_POST['pid']){
// 				return 0;
// 			}else{
// 				$data = $this->field('id,path')->getById($_POST['pid']);
// 				dump($data);
// 				return $data['path'].'-'.$data['id'];
// 			}
// 			return 'ddddddddd';
			$pid=isset($_POST['pid'])?(int)$_POST['pid']:'R';
			if($pid==0){
				return 'R';
			}
			$list=$this->where("id=$pid")->find();
			return $list['path'].'-'.$list['id'];
		}
		
	}
?>